import java.util.LinkedList;


public class DFSState {
	private int x;
	private int y;
	
	private boolean closed;
	private boolean open;
	
	private DFSState father;
	
	private Map<DFSState> map;
	
	DFSState(int x, int y, Map<DFSState> map) {
		this.x=x; 
		this.y=y;
		this.closed=false;
		this.open=false;
		this.map=map;
		this.father=null;
	}
	
	public int getX() {
		return x;
	}
	
	public int getY() {
		return y;
	}
	
	public boolean isClosed() {
		return closed;
	}
	public boolean isOpen() {
		return open;
	}
	public void close() {
		this.closed=true;
	}
	
	public void setFather(DFSState p) {
		this.father=p;
	}
	
	public DFSState getFather() {
		return this.father;
	}
	public void open() {
		this.open=true;
	}
	
	private DFSState neighbor(Direccion d) {
		int nx=this.getX()+d.X();
		int ny=this.getY()+d.Y();
		if (nx<0 || nx>=map.numColumnas() || ny<0 || ny>=map.numFilas() || !map.libre(nx,ny)) return null;
		return map.getState(nx,ny);
	}
	
	public LinkedList<DFSState> successors() {
		LinkedList<DFSState> succ=new LinkedList<DFSState>();
		for (Direccion d : Direccion.values()) {
			DFSState sucesor=neighbor(d);
			if (sucesor!=null) succ.add(sucesor);
		}
		return succ;
	}
	
	public boolean isGoal(Observacion obs) {
		return (x==obs.getGoalX() && y==obs.getGoalY());
	}
	
	
}
